#/usr/bin/python3
# -*- coding: utf-8 -*-
# 树莓派跑马灯效果

import RPi.GPIO as GPIO
import time

channels = [23, 24, 12, 16, 20, 21]

def init():

	GPIO.setmode(GPIO.BCM)
	for x in channels:
		GPIO.setup(x, GPIO.OUT)
		pass


def on(i):
	GPIO.output(i, GPIO.HIGH)


def off(i):
	GPIO.output(i, GPIO.LOW)

def ctrl(data):
	for i in channels:
#		print(i);
		GPIO.output(i, data & 0x1)
		on(i)
		time.sleep(0.1)
		off(i)
#		data = data >> 1
	pass

def ctrl1(data):
	for i in channels:
		GPIO.output(i, data & 0x1)
		data = data >> 1
	pass


def test():
#	i = 1;
#	while True:
#		ctrl1(i)
#		i += 1
#		time.sleep(0.1)
	for i in xrange(1000):
		ctrl(i)
		time.sleep(0.1)
#	i = 1
#	while True:
#		ctrl(i)
#		time.sleep(0.1)
#		i += 1
#		if i > 10:
#			ctrl1(i)
#			time.sleep(0.1)
#		if i > 20:
#			continue

def clean():
	GPIO.cleanup()


if __name__ == '__main__':
	init()
	test()
	clean()
